'use strict';
app.service('modulesGoodsAddService',['$q','utilService',function($q,utilService){
    var _this_=this;

    _this_.queryShopName= function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'shop/list'
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错");
        })
        return deferred.promise;
    }

    //添加模块商品
    _this_.addModulesGoods= function ($scope,goodsId) {

        _this_.modulesGoodsAddVO={
            modulesId:$scope.id,
            goodsId:goodsId
        };

        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'modules/goods',
            data:_this_.modulesGoodsAddVO,
            method:'POST'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    //移除模块商品
    _this_.delModulesGoods= function ($scope,id) {
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'modules/goods',
            data:{id:id},
            method:'DELETE'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

}]);